//接收前端传来的token
const basicAuth = require('basic-auth');
const jwt = require('jsonwebtoken');
const {security} = require('./tokentime');
const result = require('@/utils/handle');

class Authuid{
    get m(){
        return async(ctx,next)=>{
            const token = basicAuth(ctx.req)
            if(!token||!token.name) {
                var uid = null
            }else{
                try {
                    var authcode = jwt.verify(token.name,security.secretKey)
                    var uid = authcode.uid                     
                } catch (error) {
                    var uid = null
                }
            }
            ctx.auth = {uid}
            await next()
        }
    }
}

module.exports = {
    Authuid
}